package demo.observer;


import java.util.function.Consumer;

/**
 * @author : feixiang.li
 * @since : 2025-09-17 16:43
 */
public class User implements EventListener {

    /**
     * 用户名
     */
    private String name;

    /**
     * 消费者
     */
    private Consumer<String> consumer;

    public User(String name, Consumer<String> consumer) {
        this.name = name;
        this.consumer = consumer;
    }

    public void receiveInfo(String info) {
        consumer.accept(info);
    }

    @Override
    public void onEvent(Event event) {
        if (event instanceof WeatherUpdateEvent) {
            receiveInfo((event.source().toString()));
        }
    }
}
